package com.example.demo.config;
import java.util.HashMap;
import lombok.Data;
// AjaxResult 类用于生成 Ajax 请求的结果返回格式
@Data
public class AjaxResult {
    private int state;  // 使用state而不是code
    private String msg;  // 使用msg而不是message
    private Object data;

    private AjaxResult(int state, String msg, Object data) {
        this.state = state;
        this.msg = msg;
        this.data = data;
    }

    public static AjaxResult success(String msg, Object data) {
        return new AjaxResult(1, msg, data);  // 成功时返回1
    }

    public static AjaxResult success(Object data) {
        return new AjaxResult(1, "success", data);  // 成功时返回1，默认消息
    }

    public static AjaxResult fail(int state, String msg) {
        return new AjaxResult(state, msg, null);
    }

    public static AjaxResult fail(String msg) {
        return new AjaxResult(-1, msg, null);  // 失败时默认返回-1
    }
}
